home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10420 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  46 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!news1!ts02-and-20
  3. From: dlmiller@iquest.net (Doug & Rose Miller)
  4. Subject: Re: Converting Strings to Upper Case
  5. X-Nntp-Posting-Host: ts00-and-02.iquest.net
  6. Message-ID: <DoFA24.AL7@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Network Services
  9. X-Newsreader: News Xpress Version 1.0 Beta #2.1
  10. References: <4ifra6$52i@scipio.cyberstore.ca>
  11. Date: Sun, 17 Mar 1996 17:27:08 GMT
  12.  
  13. ejw@news.cyberstore.ca () wrote:
  14. +Hi,
  15. +
  16. +I need to write a function to convert a string containg upper or lower case
  17. +characters to the opposite case.  Something like:
  18. +
  19. +  void libConvertUpperCase(char *str);    and
  20. +  void libConvertLowerCase(char *str);
  21. +
  22. +and the string would be modified.  I just can't seem to wrap my head around
  23. +the best way that I know is better than writing a for loop to check each
  24. +element in the array?
  25. +
  26. +I apologize if this in the FAQ;  I am still going thorugh it.  Any help
  27. +would be greatly appreciated.
  28. +
  29. +Eric Woodward.
  30. +ejw@cyberstore.ca.
  31. +
  32.  
  33.  
  34. #include <stdio.h>
  35.  
  36. void main (void) {
  37. char    test[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
  38. char    *p;
  39.  
  40. printf ("%s\n", &test);
  41. for (p = test; *p; *p++)
  42.     if (isalpha(*p)) *p ^= 0x20;  /* for ascii machines e.g. PC; use 0x40 for ebcdic machines e.g. IBM mainframe */
  43. printf ("%s\n", &test);
  44. }
  45.  
  46.